import {
  Controller,
  Get,
  Post,
  UseGuards,
  Request,
  Headers,
  Res,
} from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { ApiBearerAuth } from '@nestjs/swagger';
import { response } from 'express';
import { AuthService } from './auth/auth.service';
import { Result } from './common/Result';

@Controller()
export class AppController {
  constructor(private readonly authService: AuthService) {}

  @UseGuards(AuthGuard('local'))
  @Post('auth/login')
  async login(@Request() req): Promise<Result> {
    const data = await this.authService.login(req.user);
    return {
      message: '操作成功',
      data,
    };
  }

  @ApiBearerAuth()
  @UseGuards(AuthGuard('jwt'))
  @Get('profile')
  getProfile(@Request() req) {
    return req.user;
  }
}
